
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.Iterator;
import java.util.Vector;

import edu.uclm.combTest.core.Algorithm;
import edu.uclm.combTest.core.Combination;
import edu.uclm.combTest.core.Element;
import edu.uclm.combTest.core.Set;
import edu.uclm.combTest.core.aetg.AETGAlgorithm;

/**
 * Notre implémentation.
 * 
 * @author quentin
 * 
 */
/*@ nullable_by_default @*/
public class paircov implements paircovInterf {

	static paircovInterf p;
	static String[][] tableau;

	// protected Set[] sets;
	// protected int numberOfSets=4;
	// protected int numberOfElements=5;

	public Test_Case[] generate(String[][] params_sets) {

		if (System.out == null) {
			System.setOut(new PrintStream(new OutputStream() {
				public void write(int arg0) throws IOException {
				}
			}));
		}
//		try {
//			System.setOut(new PrintStream(new File("out.html")));
//		} catch (FileNotFoundException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}

		//}
		if (params_sets.length == 0) {
			Test_Case[] tcs = new Test_Case[0];
			return tcs;

		}
		// this.sets=new Set[numberOfSets];
		// for (int i=0; i<sets.length; i++) {
		// sets[i]=new Set();
		// }
		//
		// int cont=0;
		// for (int i=0; i<sets.length; i++) {
		// cont=0;
		// for (int j=0; j<numberOfElements; j++) {
		// sets[i].add(new Element(""+cont++));
		// }
		// }
		//
		//
		// long timeIni=System.currentTimeMillis();
		// Algorithm algorithm=new AETGAlgorithm();
		// for (int i=0; i<sets.length; i++) {
		// algorithm.add(sets[i]);
		// }
		// //prepare(algorithm);
		// algorithm.buildCombinations();
		// //System.out.println(algorithm.toStringPositions());
		// //System.out.println(algorithm.toString());
		// long timeFin=System.currentTimeMillis();
		// double time=((double) (timeFin-timeIni))/1000;
		// System.out.println("Tiempo: " + time + " segundos");
		// postTest(algorithm);

		// return null;

		Algorithm algorithm = new AETGAlgorithm();
		for (int i = 0; i < params_sets.length; i++) {
			String[] params_set = params_sets[i];

			// }
			// for (String[] params_set: params_sets){
			Set set = new Set();
			for (int j = 0; j < params_set.length; j++) {
				String string = params_set[j];

				// }
				// for (String string : params_set) {
				set.add(string);
			}
			algorithm.add(set);
		}

//		System.out.println("Sets : <");
//		System.out.println(algorithm.getSets());
//		for (Iterator it = algorithm.getSets().iterator(); it.hasNext();) {
//			Set set = (Set) it.next();
//
//			// }
//			// for (Set s : algorithm.getSets()){
//			System.out.println(set.getElements());
//		}
//		System.out.println(">");
		// System.out.println(algorithm.toString());

		// return null;
		algorithm.buildCombinations();

		Vector selectedCombinations = algorithm.getSelectedCombinations();

		Test_Case[] test_Case = new Test_Case[selectedCombinations.size()];
		int i = 0;
		for (int j = 0; j < selectedCombinations.size(); j++) {
			Combination combination = (Combination) selectedCombinations.get(j);
			// }
			// for (Combination combination : allCombinations) {
			// if(i!=selectedCombinations.size()-1)
			test_Case[i] = new Test_Case(combination.size());
			for (int k = 0; k < combination.getElements().length; k++) {
				Element element = combination.getElements()[k];

				// }
				// for (Element element : combination.getElements()) {
				// if(i!=selectedCombinations.size()-1)
				test_Case[i].add(element.getValue());
			}
			i++;
		}

		return test_Case;
	}

}
